package com.puboot.module.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.puboot.common.util.CoreConst;
import com.puboot.common.util.Pagination;
import com.puboot.module.admin.mapper.BizContactMapper;
import com.puboot.module.admin.model.BizAboutUs;
import com.puboot.module.admin.model.BizContact;
import com.puboot.module.admin.service.BizContactService;
import lombok.AllArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;

import java.util.Arrays;


/**
 * @author chen
 * @version V1.0
 * @date 2021年10月18日
 */
@Service
@AllArgsConstructor
public class BizContactServiceImpl extends ServiceImpl<BizContactMapper, BizContact> implements BizContactService {

    private final BizContactMapper bizContactMapper;


    @Override
    public IPage<BizContact> pageContactAll(BizContact bizContact, Integer pageNumber, Integer pageSize) {
        IPage<BizContact> page = new Pagination<>(pageNumber, pageSize);
        return page.setRecords(bizContactMapper.selectAll(page, bizContact));
    }

    @Override
    @CacheEvict(value = "contact", allEntries = true)
    public int deleteBatch(Integer[] ids) {
        return bizContactMapper.deleteBatchIds(Arrays.asList(ids));
    }

    @Override
    public BizContact getContactUs() {
        QueryWrapper<BizContact> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", CoreConst.STATUS_VALID);
        queryWrapper.last("limit 1");
        return baseMapper.selectOne(queryWrapper);
    }


    @Override
    public BizContact findByStatus(Integer status) {
        return bizContactMapper.findByStatus(status);
    }
}
